﻿using System.Security.Principal;
using Castle.Windsor;
using RuTracker.Interface;
using RuTrackerLib;
using RuTrackerLib.Tracker.RequestProcessors;

namespace RuTracker.MVC.Models.Tracker
{
    public class TrackerModelFactory
    {
        private readonly IUserRepository _userRepository;

        public TrackerModelFactory(IWindsorContainer container)
        {
            _userRepository = container.Resolve<IUserRepository>();
        }

        public TrackerModel Create(RequestProcessingResults processingResult
            , IPrincipal user
            , string url)
        {
            return new TrackerModel
                               {
                                   Html = processingResult.Html,
                                   User = user.Identity.Name,
                                   IsTorrentAvailable = processingResult.IsTorrentAvailable,
                                   Url = QueryStringEncryptor.Encrypt(url),
                                   UserTorrent = _userRepository.GetUserTorrent(user.Identity.Name, url)
                               };
                  
        }
    }
}